﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace CarLoanSystem
{
    public partial class panelReportLoan : UserControl
    {
        public panelReportLoan()
        {
            InitializeComponent();
            genGridview();
        }

        private void genGridview()
        {
            // gen Grideview
            gvReportLoan.AutoGenerateColumns = false;

            //Set Columns Count
            gvReportLoan.ColumnCount = 8;

            //Add Columns
            gvReportLoan.Columns[0].Name = "LOAN_ID";
            gvReportLoan.Columns[0].HeaderText = "รหัส";
            gvReportLoan.Columns[0].DataPropertyName = "LOAN_ID";
            gvReportLoan.Columns[0].Width = 50;

            gvReportLoan.Columns[1].Name = "CUSTOMER_NAME";
            gvReportLoan.Columns[1].HeaderText = "ชื่อ";
            gvReportLoan.Columns[1].DataPropertyName = "CUSTOMER_NAME";
            gvReportLoan.Columns[1].Width = 80;

            gvReportLoan.Columns[2].Name = "CUSTOMER_LASTNAME";
            gvReportLoan.Columns[2].HeaderText = "นามสกุล";
            gvReportLoan.Columns[2].DataPropertyName = "CUSTOMER_LASTNAME";
            gvReportLoan.Columns[2].Width = 80;

            gvReportLoan.Columns[3].Name = "PRINCIPLE";
            gvReportLoan.Columns[3].HeaderText = "ยอดเงินที่ปล่อย";
            gvReportLoan.Columns[3].DataPropertyName = "PRINCIPLE";
            gvReportLoan.Columns[3].Width = 130;

            gvReportLoan.Columns[4].Name = "CAR_BRAND_NAME";
            gvReportLoan.Columns[4].HeaderText = "ยี่ห้อรถยนต์";
            gvReportLoan.Columns[4].DataPropertyName = "CAR_BRAND_NAME";
            gvReportLoan.Columns[4].Width = 100;

            gvReportLoan.Columns[5].Name = "CAR_MODEL_NAME";
            gvReportLoan.Columns[5].HeaderText = "รุ่นรถยนต์";
            gvReportLoan.Columns[5].DataPropertyName = "CAR_MODEL_NAME";
            gvReportLoan.Columns[5].Width = 100;

            gvReportLoan.Columns[6].Name = "CAR_TYPE_ENGINE";
            gvReportLoan.Columns[6].HeaderText = "ขนาดเครื่องยนต์";
            gvReportLoan.Columns[6].DataPropertyName = "CAR_TYPE_ENGINE";
            gvReportLoan.Columns[6].Width = 130;

            gvReportLoan.Columns[7].Name = "LOAN_STATUS";
            gvReportLoan.Columns[7].HeaderText = "สถานะ";
            gvReportLoan.Columns[7].DataPropertyName = "LOAN_STATUS";
            gvReportLoan.Columns[7].Width = 50;
            // end gen gridview
            //gvReportLoan.DataSource = LoadReportLoan();
        }

        private DataTable LoadReportLoan()
        {
            DataTable dt = DAL.ReportInfoDAL.LoadAllLoan(this.txtLoanId.Text, this.txtName.Text, this.txtLastName.Text);
            return dt;
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            gvReportLoan.DataSource = LoadReportLoan();
        }

        private void btnReport_Click(object sender, EventArgs e)
        {
            ShowReportLoan s = new ShowReportLoan(LoadReportLoan());
            s.ShowDialog();
        }
    }
}

